<template>
	<view class="device">
		<view class="head" :style="{height: pHeight + tHeight + 'px'}">
			<view class="xztitle" :style="[{height: pHeight + 'px', top: tHeight + 'px',lineHeight: pHeight + 'px'}]">
				门店收益
				<view class="iconfont icon-dayuhao1" @click="fanhui"></view>
			</view>
		</view>
		<view class="headtop" :style="{marginTop: pHeight + tHeight + 'px'}">
			<view class="sousuo">
				<view class="right">
					<input type="text" placeholder="请输入关键字" v-model="keywords" @confirm="sousuo" />
					<image :src="baseUrl + '/wximage/sousuo.png'" @click="sousuo"></image>
				</view>
			</view>
			<view class="tiaojian">
				<view class="list fl clearfix">
					<view class="name fl">总收益：¥{{zmoney}}</view>
				</view>
				<!-- <view class="list fl clearfix" @click="shouyitankuang">
					<view class="name fl">收益</view>
					<image :src="baseUrl + '/wximage/dataxl.png'"></image>
				</view>
				<view class="list fl clearfix" @click="shebeikuang">
					<view class="name fl">设备量</view>
					<image :src="baseUrl + '/wximage/dataxl.png'"></image>
				</view>
				<view class="list fl clearfix" @click="shijiankuang">
					<view class="name fl">创建时间</view>
					<image :src="baseUrl + '/wximage/dataxl.png'"></image>
				</view>
				<view class="list fl clearfix" @click="shishoukuang">
					<view class="name fl">实收金额</view>
					<image :src="baseUrl + '/wximage/dataxl.png'"></image>
				</view> -->
				<view class="more fr clearfix">
					<picker mode="date" header-text="选择时间" fields="month" @change="selectDataTime">
						<view class="text fl">{{month}}</view>
						<image :src="baseUrl + '/wximage/dataxl.png'"></image>
					</picker>
				</view>
			</view>
			<!-- <view class="bottom clearfix">
				<view class="left fl">
					总收益：¥{{zmoney}}
				</view>
				<view class="right fr clearfix" @click="moretankuang">
					<image :src="baseUrl + '/wximage/shaixuan.png'" class="fl"></image>
					<view class="name fl">筛选</view>
				</view>
			</view> -->

			<!-- <view class="beijing" v-if="bjstatus" @click="guanbi"></view>
			<view class="tankuang" v-if="shouyistatus">
				<view class="liebiao">
					<view class="wenzi">全部</view>
				</view>
				<view class="liebiao">
					<view class="wenzi">从低到高</view>
					<image :src="baseUrl + '/wximage/shaixuanbj.png'"></image>
				</view>
				<view class="liebiao">
					<view class="wenzi">从高到低</view>
				</view>
			</view>
			<view class="tankuang" v-if="shebeistatus">
				<view class="liebiao">
					<view class="wenzi">全部</view>
				</view>
				<view class="liebiao">
					<view class="wenzi">从少到多</view>
					<image :src="baseUrl + '/wximage/shaixuanbj.png'"></image>
				</view>
				<view class="liebiao">
					<view class="wenzi">从多到少</view>
				</view>
			</view>
			<view class="tankuang" v-if="shijianstatus">
				<view class="liebiao">
					<view class="wenzi">全部</view>
				</view>
				<view class="liebiao">
					<view class="wenzi">从前往后</view>
					<image :src="baseUrl + '/wximage/shaixuanbj.png'"></image>
				</view>
				<view class="liebiao">
					<view class="wenzi">从后往前</view>
				</view>
			</view>
			<view class="tankuang" v-if="shishoustatus">
				<view class="liebiao">
					<view class="wenzi">全部</view>
				</view>
				<view class="liebiao">
					<view class="wenzi">从低到高</view>
					<image :src="baseUrl + '/wximage/shaixuanbj.png'"></image>
				</view>
				<view class="liebiao">
					<view class="wenzi">从高到低</view>
				</view>
			</view> -->
		</view>
		<!--<view class="morebeijing" v-if="morebjstatus" @click="guanbi"></view>
		<view class="moretankuang" v-if="morestatus">
			<view class="bankuai">
				<view class="top">实收金额<text class="chongzhi">重置</text></view>
				<view class="shurubottom">
					<view class="tishi">请输入实收金额区间</view>
					<view class="shuru clearfix">
						<input type="text" placeholder="0" class="fl" value="0" />
						<text class="fl">至</text>
						<input type="text" placeholder="99999" value="99999" class="fl" />
					</view>
				</view>
			</view>
			<view class="bankuai">
				<view class="top">订单数<text class="chongzhi">重置</text></view>
				<view class="shurubottom">
					<view class="tishi">请输入订单数区间</view>
					<view class="shuru clearfix">
						<input type="text" placeholder="0" class="fl" value="0" />
						<text class="fl">至</text>
						<input type="text" placeholder="99999" value="99999" class="fl" />
					</view>
				</view>
			</view>
			<view class="queren" @click="queren">
				确认
			</view>
		</view> -->
		<view class="content" v-if="list.length != 0">
			<view class="list" v-for="(item,index) in list" :key="index">
				<view class="top clearfix">
					<image :src="baseUrl + '/wximage/hktubiao.png'" class="fl"></image>
					<view class="title fl">{{item.name}}</view>
				</view>
				<view class="shuju clearfix" v-if="role_id != 12">
					<view class="liebiao">
						<view class="shuzi">{{item.ordercount}}</view>
						<view class="names">订单数(笔)</view>
					</view>
					<view class="liebiao">
						<view class="shuzi">{{item.shishoumoney}}</view>
						<view class="names">实收金额(元)</view>
					</view>
					<view class="liebiao">
						<view class="shuzi">{{item.wodemoney}}</view>
						<view class="names">我的收益(元)</view>
					</view>
				</view>
				<view class="shuju shujus clearfix" v-else>
					<view class="liebiao">
						<view class="shuzi">{{item.ordercount}}</view>
						<view class="names">订单数(笔)</view>
					</view>
					<view class="liebiao">
						<view class="shuzi">{{item.wodemoney}}</view>
						<view class="names">我的收益(元)</view>
					</view>
				</view>
				<view class="center">前{{item.ptmianfei}}分钟免费，{{item.ptdanjia}}，日封顶：{{item.ptrfengding}}元，总封顶{{item.ptfengding}}元</view>
				<view class="center center1">前{{item.kcmianfei}}分钟免费，{{item.kcdanjia}}，日封顶：{{item.kcrfengding}}元，总封顶{{item.kcfengding}}元</view>
				<view v-if="limits.endorder == true && role_id != 12">
					<view class="bottom clearfix" v-if="station_id != item.id" @click="shouyidetail(index)">
						<view class="name">收益详情</view>
						<image :src="baseUrl + '/wximage/right.png'"></image>
					</view>
					<view v-else>
						<view class="bottom bottomts clearfix" @click="station_id = ''">
							<view class="name">收益详情</view>
							<image :src="baseUrl + '/wximage/xia.png'"></image>
						</view>
						<view class="bottom clearfix">
							<view class="desc">设备数量(台)：{{detail.sbcount}}</view>
							<view class="desc">订单金额(元)：{{detail.ymoney}}</view>
							<view class="desc">优惠金额(元)：{{detail.jmmoney}}</view>
							<view class="desc">退款金额(元)：{{detail.tkmoney}}</view>
							<view class="desc">订单收益(元)：{{detail.ddshouyimoney}}</view>
							<view class="desc" v-if="role_id != 12 && role_id != 13">丢/买宝收益(元)：{{detail.baoshouyimoney}}</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="empty" v-else>
			<image :src="baseUrl + '/wximage/empty.png'"></image>
			<text>暂无相关数据</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				baseUrl: getApp().globalData.baseUrl,
				headerTop: 0,
				pHeight: 0,
				tHeight: 0,
				keywords: '',
				list: [],
				bjstatus: false,
				keystatus: false,
				shouyistatus: false,
				shebeistatus: false,
				shijianstatus: false,
				shishoustatus: false,
				morebjstatus: false,
				morestatus: false,
				month: '',
				page: 1,
				pageSize: 10,
				total: 0,
				agent_id: '',
				role_id: '',
				zmoney: '0.00',
				station_id: '',
				detail: {
					sbcount: 0,
					ymoney: 0,
					jmmoney: 0,
					tkmoney: 0,
					ddshouyimoney: 0,
					baoshouyimoney: 0,
				},
				limits: {
					orderfind: false,//订单查看
					payouts: false,//分成比例
					endorder: false,//收益记录
					returnorder: false,//按日统计
				}
			}
		},
		onLoad() {
			// 头部距离
			let res = uni.getSystemInfoSync() ///微信api方法
			let titleH;
			if (res && res['system']) {
				// 判断是否是安卓操作系统 （标题栏苹果为44px,安卓为48px）
				if (res['system'].indexOf('Android') > 0) {
					titleH = 48
				} else {
					titleH = 46
				}
				this.headerTop = titleH + res['statusBarHeight']
				this.pHeight = titleH
				this.tHeight = res['statusBarHeight']
			}
			
			this.agent_id = uni.getStorageSync('agent_id');
			this.role_id = uni.getStorageSync('role_id');
			
			// 获取用户信息
			this.request({
				url: '/agent/users',
				data: {
					id: this.agent_id,
				},
				method: "POST"
			}).then(res => {
				if (res.data.code == 200) {
					let arr = JSON.parse(res.data.data.cities);
					this.limits = arr;
				} else {
					uni.showToast({
						title: '请求失败，请稍后再试',
						icon: 'none'
					})
				}
			})
			
			this.month = this.getNowFormatDate();
			
			this.getList(this.page,this.pageSize,this.month,this.keywords);
			this.getZshouyi(this.month,this.keywords);
		},
		onReachBottom() {
			if(this.total != this.list.length){
				this.page = this.page+1;
				this.getList(this.page,this.pageSize,this.month,this.keywords);
			}
		},
		methods: {
			getList(page,pageSize,month,keywords){
				this.request({
					url: '/xcx/storeincome',
					data: {
						agent_id: this.agent_id,
						role_id: this.role_id,
						page: page,
						pageSize: pageSize,
						month: this.month,
						keywords: keywords,
					},
					method: "POST"
				}).then(res => {
					if (res.data.code == 200) {
						this.total = res.data.data.total;
						this.list = this.list.concat(res.data.data.data);
					} else {
						uni.showToast({
							title: '请求失败，请稍后再试',
							icon: 'none'
						})
					}
				})
			},
			getZshouyi(month,keywords){
				this.request({
					url: '/xcx/storezshouyi',
					data: {
						agent_id: this.agent_id,
						role_id: this.role_id,
						month: this.month,
						keywords: keywords,
					},
					method: "POST"
				}).then(res => {
					if (res.data.code == 200) {
						this.zmoney = res.data.data.zmoney;
					} else {
						uni.showToast({
							title: '请求失败，请稍后再试',
							icon: 'none'
						})
					}
				})
			},
			sousuo(){
				this.page = 1;
				this.total = 0;
				this.month = this.getNowFormatDate();
				this.list = [];
				
				this.getList(this.page,this.pageSize,this.month,this.keywords);
				
				this.getZshouyi(this.month,this.keywords);
			},
			//门店收益详情
			shouyidetail(index){
				this.station_id = this.list[index].id;
				
				this.request({
					url: '/xcx/storesydetail',
					data: {
						agent_id: this.agent_id,
						role_id: this.role_id,
						month: this.month,
						station_id: this.station_id,
					},
					method: "POST"
				}).then(res => {
					if (res.data.code == 200) {
						this.detail = res.data.data;
					} else {
						uni.showToast({
							title: '请求失败，请稍后再试',
							icon: 'none'
						})
					}
				})
			},
			keytankuang() {
				this.bjstatus = true;
				this.keystatus = true;
				this.shouyistatus = false;
				this.shebeistatus = false;
				this.shijianstatus = false;
				this.shishoustatus = false;
				this.morestatus = false;
				this.morebjstatus = false;
			},
			shouyitankuang() {
				this.bjstatus = true;
				this.shouyistatus = true;
				this.shebeistatus = false;
				this.shijianstatus = false;
				this.shishoustatus = false;
				this.morestatus = false;
				this.morebjstatus = false;
			},
			shebeikuang() {
				this.bjstatus = true;
				this.keystatus = false;
				this.shouyistatus = false;
				this.shebeistatus = true;
				this.shijianstatus = false;
				this.shishoustatus = false;
				this.morestatus = false;
				this.morebjstatus = false;
			},
			shijiankuang() {
				this.bjstatus = true;
				this.keystatus = false;
				this.shouyistatus = false;
				this.shebeistatus = false;
				this.shijianstatus = true;
				this.shishoustatus = false;
				this.morestatus = false;
				this.morebjstatus = false;
			},
			shishoukuang() {
				this.bjstatus = true;
				this.keystatus = false;
				this.shouyistatus = false;
				this.shebeistatus = false;
				this.shijianstatus = false;
				this.shishoustatus = true;
				this.morestatus = false;
				this.morebjstatus = false;
			},
			moretankuang() {
				this.bjstatus = false;
				this.keystatus = false;
				this.shouyistatus = false;
				this.shebeistatus = false;
				this.shijianstatus = false;
				this.shishoustatus = false;
				this.morebjstatus = true;
				this.morestatus = true;
			},
			guanbi() {
				this.bjstatus = false;
				this.morebjstatus = false;
				this.keystatus = false;
				this.shouyistatus = false;
				this.shebeistatus = false;
				this.shijianstatus = false;
				this.shishoustatus = false;
				this.morestatus = false;
				this.morebjstatus = false;
			},
			selectDataTime(e) {
				this.month = e.detail.value;
				this.page = 1;
				this.total = 0;
				this.list = [];
				
				this.getList(this.page,this.pageSize,this.month,this.keywords);
				
				this.getZshouyi(this.month,this.keywords);
			},
			getNowFormatDate() {
			  let date = new Date(),
			    year = date.getFullYear(), //获取完整的年份(4位)
			    month = date.getMonth() + 1, //获取当前月份(0-11,0代表1月)
			    strDate = date.getDate() // 获取当前日(1-31)
			  if (month < 10) month = `0${month}` // 如果月份是个位数，在前面补0
			  if (strDate < 10) strDate = `0${strDate}` // 如果日是个位数，在前面补0
			 
			  return `${year}-${month}`
			},
			fanhui() {
				uni.navigateBack();
			}
		}
	}
</script>

<style lang="scss">
	page{
		background: #f9f9ff;
	}
	
	.device {
		width: 100%;
		margin: 0 auto;

		.head {
			width: 100%;
			position: fixed;
			top: 0;
			left: 0;
			z-index: 99;
			background: linear-gradient(90deg, #f9f9ff, #d4e8ff);

			.xztitle {
				position: fixed;
				left: 0%;
				top: 0;
				width: 100%;
				text-align: left;
				color: #333333;
				font-size: 32rpx;
				padding-left: 74rpx;
				font-weight: 700;

				text {
					font-size: 24rpx;
				}

				.iconfont {
					position: absolute;
					top: 0;
					left: 30rpx;
					font-size: 44rpx;
				}
			}
		}

		.headtop {
			width: 100%;
			background: linear-gradient(90deg, #f9f9ff, #d4e8ff);
			height: 190rpx;
			position: relative;

			.sousuo {
				width: 100%;
				padding: 20rpx 40rpx;
				box-sizing: border-box;

				.left {
					height: 60rpx;
					line-height: 60rpx;

					.name {
						color: #666666;
					}

					image {
						width: 44rpx;
						height: 44rpx;
						margin-top: 8rpx;
					}
				}

				.right {
					position: relative;
					width: 100%;

					input {
						height: 60rpx;
						line-height: 60rpx;
						background: #ffffff;
						border-radius: 30rpx;
						padding-left: 30rpx;
						color: #999999;
					}

					image {
						width: 72rpx;
						height: 40rpx;
						position: absolute;
						right: 10rpx;
						top: 10rpx;
						z-index: 10;
					}
				}
			}

			.tiaojian {
				width: 100%;
				background: rgba(139, 140, 255, 0.1);
				height: 72rpx;
				line-height: 72rpx;
				padding: 0 20rpx 0 40rpx;

				.list {
					margin-right: 4rpx;
					height: 72rpx;
					line-height: 72rpx;

					.name {
						color: #333333;
						font-size: 24rpx;
						font-weight: 700;
						overflow: hiddden;
						text-overflow: ellipsis;
						white-space: nowrap;
					}

					image {
						width: 44rpx;
						height: 44rpx;
						margin-top: 14rpx;
					}
				}

				.more {

					.text {
						font-size: 24rpx;
						color: #5C88FA;
					}

					image {
						width: 44rpx;
						height: 44rpx;
						margin-top: 14rpx;
					}
				}
			}

			.bottom {
				width: 100%;
				margin-top: 20rpx;
				padding: 0 40rpx;

				.left {
					font-size: 28rpx;
					color: #333333;
					font-weight: 700;
				}

				.right {
					width: 120rpx;
					height: 36rpx;
					line-height: 36rpx;
					text-align: center;
					background: #FFFFFF;
					border-radius: 24rpx;

					image {
						width: 36rpx;
						height: 36rpx;
						margin-left: 10rpx;
						margin-right: 6rpx;
					}

					.name {
						font-size: 24rpx;
						color: #333333;
					}
				}
			}
		}

		.content {
			width: 100%;
			padding: 0 40rpx;
			box-sizing: border-box;
			margin-top: 20rpx;

			.list {
				width: 100%;
				background: #fff;
				border-radius: 20rpx;
				margin-bottom: 20rpx;
				padding: 20rpx;
				box-shadow: rgba(223, 230, 255, 0.67) 0px 0px 6px;

				.top {
					width: 100%;
					border-bottom: 1rpx solid #F1F1F1;
					padding-bottom: 20rpx;

					image {
						width: 40rpx;
						height: 40rpx;
						margin-right: 10rpx;
						margin-top: -6rpx;
					}

					.title {
						font-size: 28rpx;
						color: #333333;
						font-weight: 700;
						
						.zhuangtai{
							color: #999999;
						}
						
						.zhuangtai1{
							color: #15827F;
						}
					}
				}
				
				.shuju {
					width: 96%;
					margin: 0 auto;
					margin-top: 20rpx;
					border-bottom: 1rpx solid #F1F1F1;
					padding-bottom: 20rpx;
				
					.liebiao {
						width: 33.3%;
						text-align: center;
						float: left;
				
						.shuzi {
							font-size: 40rpx;
							color: #333333;
							font-weight: 700;
							margin-bottom: 10rpx;
						}
				
						.names {
							font-size: 24rpx;
							color: #333333;
						}
					}
				}
				
				.shujus {
				
					.liebiao {
						width: 50%;
					}
				}

				.center {
					width: 96%;
					margin: 0 auto;
					margin-top: 24rpx;
					font-size: 20rpx;
					color: #368BF8;
				}
				
				.center1{
					margin-top: 4rpx;
				}

				.bottom {
					width: 96%;
					margin: 0 auto;
					margin-top: 24rpx;
					position: relative;

					.name {
						width: 90%;
						font-size: 24rpx;
						color: #333333;
						float: left;
						line-height: 36rpx;
					}

					.desc {
						width: 90%;
						font-size: 24rpx;
						color: #333333;
						line-height: 44rpx;
					}

					image {
						width: 30rpx;
						height: 30rpx;
						position: absolute;
						top: 0;
						right: 0;
					}
				}
				
				.bottomts{
					border-bottom: 1rpx solid #F1F1F1;
					padding-bottom: 24rpx;
				}
			}
		}

		.empty {
			width: 100%;
			margin: 200rpx auto 0;
			text-align: center;

			image {
				width: 390rpx;
				height: 340rpx;
			}

			text {
				display: block;
				margin-top: 60rpx;
				font-size: 24rpx;
				color: #666666;
			}
		}

		.morebeijing {
			position: absolute;
			bottom: 0;
			left: 0;
			width: 100%;
			height: 100vh;
			background: #000000;
			opacity: 0.5;
			z-index: 100;
		}

		.moretankuang {
			position: absolute;
			bottom: 0;
			left: 0;
			width: 100%;
			height: 750rpx;
			background: #fff;
			z-index: 200;
			border-top-left-radius: 20rpx;
			border-top-right-radius: 20rpx;
			padding: 20rpx 0;

			.bankuai {

				.top {
					background: #FDFDFD;
					font-size: 32rpx;
					color: #333333;
					height: 72rpx;
					line-height: 72rpx;
					padding-left: 40rpx;
					box-sizing: border-box;
					border-bottom: 1rpx solid #DFE6FF;
					position: relative;

					.chongzhi {
						position: absolute;
						top: 8rpx;
						right: 40rpx;
						width: 136rpx;
						height: 48rpx;
						line-height: 48rpx;
						text-align: center;
						border-radius: 16rpx;
						color: #333333;
						background: #E3F2FF;
						font-size: 24rpx;
					}

				}

				.shurubottom {
					margin-top: 20rpx;
					margin-bottom: 50rpx;
					width: 100%;
					padding: 0 40rpx;

					.tishi {
						font-size: 24rpx;
						color: #333333;
					}

					.shuru {
						width: 60%;
						margin: 0 auto;
						text-align: center;
						height: 50rpx;
						line-height: 50rpx;
						margin-top: 40rpx;

						input {
							width: 33.3%;
							text-align: center;
							height: 50rpx;
							line-height: 50rpx;
							color: #3B91F8;
							border-bottom: 1rpx solid #E3F2FF;
						}

						text {
							display: inline-block;
							width: 33.3%;
						}
					}
				}
			}

			.queren {
				width: 180rpx;
				margin: 0 auto;
				height: 60rpx;
				line-height: 60rpx;
				border-radius: 16rpx;
				text-align: center;
				background: #3B91F8;
				margin-top: 100rpx;
				font-size: 28rpx;
				color: #FFFFFF;
			}
		}

		.beijing {
			position: absolute;
			top: 174rpx;
			left: 0;
			width: 100%;
			height: 78vh;
			background: #000000;
			opacity: 0.5;
			z-index: 100;
		}

		.tankuang {
			position: absolute;
			top: 174rpx;
			left: 0;
			width: 100%;
			height: 400rpx;
			background: #fff;
			overflow-y: scroll;
			z-index: 200;
			border-bottom-left-radius: 20rpx;
			border-bottom-right-radius: 20rpx;
			padding: 20rpx 0;

			.liebiao {
				width: 100%;
				height: 72rpx;
				line-height: 72rpx;
				text-align: center;
				position: relative;

				.wenzi {
					font-size: 24rpx;
					color: #999999;
				}

				image {
					width: 100%;
					height: 72rpx;
					position: absolute;
					top: 0;
					left: 0;
				}
			}
		}
	}
</style>